Revision: tla--no-direct-reltable-slot-access--1.3.1--versionfix-1
Archive: lord@emf.net--libawk-exp-2005
Creator: Thomas Lord <lord@emf.net>
Date: Sat Feb 12 22:39:45 PST 2005
Standard-date: 2005-02-13 06:39:45 GMT
New-patches: lord@emf.net--libawk-exp-2005/tla--no-direct-reltable-slot-access--1.3.1--versionfix-1
Summary: log message
Keywords: 

  Relational tables were publicly declared this way:

  [[tty
    typedef t_uchar * rel_field;
    typedef rel_field * rel_record;
    typedef rel_record * rel_table;
  ]]

  Consequently, client code could (and in some instances did) use the
  following and similar idioms to modify a relational table element's
  value:

  [[tty
	rel_table a_table;

        [...]

        old_value = a_table[x][y];
        a_table[x][y] = str_save (0, new_value);
        lim_free (0, old_value);
  ]]

  Such client code errantly presumes too much about how table elements
  are allocated and freed and the direct assignment into a table
  obligates the `libawk' implementation to honor the client's
  expectations about memory management.

  This change fixes that problem by first changing the declaration
  of a relational table to:

  [[tty
    struct rel_field
    {
      t_uchar * _f;
    };

    typedef struct rel_field rel_field;
    typedef rel_field * rel_record;
    typedef rel_record * rel_table;
  ]]

  and then fixing, in the simplest way, all other code broken
  by that change.

  Two new functions, `rel_ref_str' and `rel_set_str' are introduced.
  Those functions replace direct references to relational table slots
  this way:

  [[tty
               New Procedural Abstractions in `libawk'


	old idiom:			new idiom:

       s = table[x][y];		      s = rel_ref_str (table, x, y);


       table[x][y] 		      rel_set_str (table, x, y, s);
         = str_save (0, s);
  ]]


  (Note the slight change in memory management discipline in the
  second row of the table above.)

